<?php
namespace Home\Controller\SuperUser;
use Think\Controller;
/*
 * 超级店铺管理员 2016.6.6
 * author:candy
 */

class ShopController extends Controller {
	/**
	 * 店铺管理
	 */
    public function index(){

    }

/**
 * 7.3
 * 显示审核的界面
 * [verifyShop 店家审核界面，包括用户申请的资料，
 * 	word 下载下来查看
 * ]
 * @return [type] [description]
 */
    public function verifyShop($id=null){
    	$shop = M('shop');
    	if($id){
    		$oneshop = $shop->where('shop_id='.$id)->find();
    		$this->assign('shop',$oneshop);
    		dump($oneshop);
    	}
    	$this->display("Test:testverify");
    }

/**
 * 7.3
 * [listShop 列出所有店家/或者根据id 找出具体的商家]
 * @return [type] [description]
 */
    public function listShop($id=null,$shopname=null,$status=null){
	    $shop = M('shop');
    	if($id){
    		$oneshop = $shop->where('shop_id='.$id)->find();
    		$this->assign('shop',$oneshop);
    		dump($oneshop);
    		$this->display('SuperUser/shop/verify');
    	}else if($shopname){
    		$map['name'] = array('LIKE','%'.$shopname.'%');
    		$shoplist = $shop->where($map)->select();
    		$this->assign('shoplist',$shoplist);
    		// dump($shoplist);
    		$this->display('SuperUser/shop/verify');
    	}else if($status){
    		$shoplist = $shop->where('status='.$status)->select();
    		$this->assign('shoplist',$shoplist);
    		// dump($shoplist);
            switch ($status) {
                case '1':
                    $this->display('SuperUser/shop/verify');
                    /**
                     * 加入历史审批状态
                     * 已处理？审批中
                     */
                    break;
                case '2':
                    $this->display('SuperUser/shop/normal');
                    break;
                case '3':
                    $this->display('SuperUser/shop/black');
                    break;
                
                default:
                    $this->display('SuperUser/shop/normal');
                    break;
            }
    	}else{
	    	$list = $shop->select();
	    	$this->assign('shoplist',$list);
	        $this->display('SuperUser/shop/verify');
    	}
    }

/**
 * 7.7
 * 商家详情
 */
    public function shopprofile($id=null){
        $shop = M('shop');
        if($id){
            $oneshop = $shop->where('shop_id='.$id)->find();
            $this->assign('shop',$oneshop);
            // dump($oneshop);
            $this->display('SuperUser/shop/profile');
        }
    }

/**
 * 7.3 修改店家的状态
 * 1表示正在审核，2表示审核通过，3表示商店审核不通过或者被封禁
 */
	public function manageShop($id=null,$status=null){
		$shop = M('shop');
    	if($id&&$status){
    		$shop->status = $status;
    		if($shop->where('shop_id='.$id)->save()){
                redirect(U('Home/Superuser/shop/shopprofile/id/'.$id));
    			// $this->success('修改成功',U('Home/SuperUser/shop/shopprofile/id/'.$id),2);
    		}else{
                redirect(U('Home/Superuser/shop/shopprofile/id/'.$id));
    			// $this->error('没有修改',U('Home/SuperUser/shop/shopprofile/id/'.$id),2);
    		}
    	}else{
            redirect(U('Home/Superuser/shop/shopprofile/id/'.$id));
	    	// $this->error('违法操作',U('Home/SuperUser/shop/shopprofile/id/'.$id),2);
    	}
	}

/**
 * 7.3
 * 批量禁用(ids列表进行修改)
 * 可以留着备用
 */
	public function ban(){
		$list = I('post.ids');
		foreach ($list as $key => $id) {
			$this->manageShop($id,3);
		}
	}

}